package com.itheima.app.controller;

import cn.hutool.db.PageResult;
import com.itheima.app.manager.UserLikeManager;
import com.itheima.domain.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserLikeController {
    @Autowired
    private UserLikeManager userLikeManager;

    //互相喜欢，喜欢，粉丝 - 统计
    @GetMapping("/users/counts")
    public ResponseEntity counts(){
        return userLikeManager.counts();
    }

    @GetMapping("/users/friends/{type}")
    public ResponseEntity friendsType(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pageSize,
                                      @PathVariable Integer type) {
        try {
            PageBeanVo pageBeanVo = userLikeManager.queryLikeList( page, pageSize,type);
            return ResponseEntity.ok(pageBeanVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    //粉丝 - 喜欢
    @PostMapping("/users/fans/{uid}")
    public ResponseEntity fans(@PathVariable String uid){
        System.out.println("打印看看这个id是什么id"+uid);

        userLikeManager.fans(uid);

        return ResponseEntity.ok(null);
    }

    //喜欢 - 取消
    @DeleteMapping("/users/like/{uid}")
    public ResponseEntity deleteLike(@PathVariable String uid){
        System.out.println("打印看看这个id是什么id"+uid);

        userLikeManager.deleteLike(uid);

        return ResponseEntity.ok(null);
    }
}
